<!--
 * @Description: 
 * @Author: chenjiaxin
 * @Date: 2022-03-01 19:22:46
 * @LastEditTime: 2022-03-02 21:36:48
 * @FilePath: \WebSkillExtend\eg8-apply-bind-call函数实现\index.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>apply-bind-call</title>
  </head>
  <body>
    <script>
      Function.prototype.myCall = function (thisArg, ...args) {
        // console.log("call", this, thisArg, args);
        // Function.name;
        // console.log(this.name);
        var _fn = this;
        // thisArg.fn = _fn;
        thisArg =
          thisArg != null || thisArg != undefined ? Object(thisArg) : window;

        thisArg.fn = _fn;
        var result = thisArg.fn(...args);
        delete thisArg.fn;
        return result;
      };
      function fn() {
        console.log("我是fn函数", this);
      }
      var obj = { name: "cjx" };
      // fn.myCall(obj, "1", "2");
    </script>
    <script>
      function handle(n, m) {
        console.log("Handle函数", this, n, m);
      }
      //系统的call 函数
      var info = { name: "A" };
      // var result = handle.call(info, 2, 3);
      // console.log(result);

      handle.apply(info, [1, 2]);
    </script>
  </body>
</html>
